package com.smarthome.rpc.impl;

import javax.annotation.Resource;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.smarthome.rpc.HkVideoService;
import com.smarthome.rpc.base.BaseRpcService;
import com.smarthome.rpc.hkVideo.GetCameraInfoController;
import com.smarthome.rpc.hkVideo.TokenController;

@Service("hkvideoService")
public class HkVideoServiceImpl extends BaseRpcService implements HkVideoService {
	private static final Logger LOGGER = LoggerFactory.getLogger(HkVideoServiceImpl.class);
	private final static String PRE_LOGGER = "[HkVideoServiceImpl]";
	@Resource
	TokenController hktokencontroller;
	@Resource
	GetCameraInfoController hkGetCameraInfoController;

	@Override
	public String getAccessToken() {
		// TODO Auto-generated method stub
		String restult = "";
		try {
			restult = hktokencontroller.getAccessToken();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throwsRpcConnectException("从海康萤石云获取accessToken异常", e);
		}
		return restult;
	}

	@Override
	public String getCameraInfo(String cameraSerial) {
		// TODO Auto-generated method stub
		String rtnStr = "";
		try {
			rtnStr = hkGetCameraInfoController.getCamerainfo(cameraSerial);
			if (StringUtils.isNotBlank(rtnStr)) {
				return rtnStr;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			LOGGER.info(PRE_LOGGER + "从海康萤石云获取摄像头状态信息失败。设备序列号[" + cameraSerial + "],错误信息[" + e.getMessage() + "].");
			return rtnStr;
		}

		return rtnStr;

	}

}
